<?php
namespace app\index\model;
use think\Db;
use think\Model;

class Users extends Model
{
	//个人详情查询
    public static function selOne($uid){
    	 $userOne=Db::name('user_info')
    	           ->field('uid,nickname,key_word,loginSecret,openid,update_time,latitude,longitude,userPhoto,focusNum') 
    	           ->where(['uid'=>$uid,'userFlag'=>'1']) 
    	           ->find();
         return $userOne;
    }
    //用户手机号检测
    public static function phoneSel($userPhone){
       $userOne=Db::name('user_info')
                 ->field('uid,nickname,key_word,loginSecret,openid,update_time,latitude,longitude') 
                 ->where(['userPhone'=>$userPhone,'userFlag'=>'1']) 
                 ->find();
         return $userOne;
    }
	//个人详情查询
    public static function userSel($nearby_id){
    	 $user_info=Db::name('user_info')
    	           ->where(['uid'=>$nearby_id,'userFlag'=>'1'])
    	           ->field('uid as nearby_id,gender,birthday,height,university,userPhoto,nickname,city,sef_desc,constellation,marriage,fans,attention,key_word,userImg1,latitude,longitude,userImg2,userImg3,userImg4,userImg5,userImg6')
    	           ->find();
        if(empty($user_info)){
          return $user_info;
        }         
    	// // 重组图片
            $imgs=[$user_info['userImg6'],$user_info['userImg1'],$user_info['userImg2'],$user_info['userImg3'],$user_info['userImg4'],$user_info['userImg5']];
                //print_r($imgs);die;
                $imgList=array();
                foreach ($imgs as $k => $img) {
                    if(!empty($img)){
                        $imgList[]=$img;
                    }
                }
                $user_info['ImgList']=$imgList;
             if(!empty($user_info['key_word'])){
               //查询性格关键字 
              $keyword=Db::name('keyword')
             ->field('keyName')
             ->where('id','in',$user_info['key_word']) 
             ->select();
        //判断是否关注过                
        $user_info['keywordList']=$keyword;    
             }         
         return $user_info;
    }
    //会员搜索
    public static function member($nickname){
        $where="nickname".' '.'like'.' '."'".'%'.$nickname.'%'."'";
       $memberList=Db::name('user_info')->where($where)->field('uid as nearby_id,nickname,userPhoto')->select();
       return $memberList;
    }
    //领队搜索
    public static function teamSet($captainName){
        $where="name".' '.'like'.' '."'".'%'.$captainName.'%'."'";
       $memberList=Db::name('captain_info')->where($where)->field('id as captain_id,name,captainPhoto')->select();
       return $memberList;
    }
    //添加注销
    public static function forbiddenAdd($data){
         $rs=Db::name('user_forbidden')->insert($data);
         return $rs;
    }
    //判断是否已经申请注销啦
      public static function forbiddenSel($uid){
         $forbid=Db::name('user_forbidden')->field('uid,name')->where(['uid'=>$uid])->select();
         return $forbid;
    }
    //修改用户的通知状态
    public static function inform($uid,$data){
      $informd=Db::name('user_info')->where(['uid'=>$uid])->update($data);
         return $informd;
    }
    //查询签到时间
    public static function userSign($uid){
        $user_daily=Db::name('user_daily')->where(['uid'=>$uid])->find();
         return $user_daily; 
    } 
 

}